<?php
//$catid=
// Declare environment connect to database
include("include.php");
//Khoi tao mot session hoac lay lai gia tri trong cookie

$proid = $_GET["proid"];
$act = $_GET["act"];
$arr_cart = array();
if (session_is_registered('session_arr_cart')){
	//echo "da dk session_arr_cart<br>";
	//print_r ($_SERVER);
	
	$arr_cart = $_SESSION["session_arr_cart"];
	//print_r ($arr_cart);
	//kiem tra xem co trong array chua?
	$found = 0;
	foreach ($arr_cart as $key => $value){
		if($key == $proid){
			$found = 1;
		}
	}
	if ($found > 0){
		if($act == "remove"){
			unset ($arr_cart[$proid]);
		}else{
			$arr_cart[$proid] = $arr_cart[$proid] + 1;
		}
	}else{
		$arr_cart[$proid] = 1;
	}

	
	session_unregister('session_arr_cart');
	$session_arr_cart = $arr_cart;
	session_register('session_arr_cart');

}else{
	//khoi tao bien
	//echo "chua dk session_arr_cart<br>";
	$session_arr_cart = array(
			"$proid"=>"1"
					);
	session_register('session_arr_cart');
}


//print_r ($session_arr_cart);

//$str_htm = get_session("Pro_ID");
//$str_htm.= "<br>".$HTTP_REFERER;
//$return_page = $HTTP_REFERER;
//echo "return_page: $return_page<br>";

//echo "<br><a href='viewcart.php?return_page=".$return_page."'>View cart</a>";

//*
echo("<script>document.location='viewcart.php?langid=$langid&return_page=$return_page'</script>");
//*/

//print $str_htm;
?>